select 'print "create grant permission to current db"'+char(10)+char(10)

set nocount on
go

SELECT 
   CASE WHEN p.protecttype < 2 THEN 'grant' ELSE 'revoke' END  +
   CASE p.action   
       when 151 then ' references'
       when 193 then ' select'
       when 195 then ' insert'
       when 196 then ' delete'
       when 197 then ' update'
       when 224 then ' execute'
       else ''
   END +
   ' on ' + user_name(so.uid)+'.'+ object_name(p.id) +
   CASE when p.protecttype < 2 then ' to' else 'from' end +
   CASE when p.protecttype = 0 then ' with grant option ' else ' ' end +
   + user_name(p.uid)+' ' + char(13) + char(10) + 'go' + char(13) + char(10)
FROM 
       sysprotects  p,
       sysobjects   so
WHERE 
       p.action in (151, 193, 195, 196, 197, 224) AND
	    p.protecttype in (0,1,2)    AND  
       p.id            = so.id     AND
       so.type in      ('U', 'P')  
ORDER BY 
       object_name(p.id)

set nocount off
go
